package com.lzj.demo.design.strategy.fzw;

import org.springframework.stereotype.Component;

import java.math.BigDecimal;
/**
 * 满减计算
 * 1.判断满足x元后-N元,否则不减
 * 2.最低支付金额1元
 * */
@Component
public class MJCoupon implements ICoupon{
    @Override
    public BigDecimal discountAccount(BigDecimal skuPrice) {
        //小于商品满减条件，直接返回商品原价
        if(skuPrice.compareTo(CouponEnum.MJ.getPrice())< 0){
            return skuPrice;
        }
        //减去优惠券金额判断
        BigDecimal discountAmount = skuPrice.subtract(CouponEnum.MJ.getPrice());
        if(discountAmount.compareTo(BigDecimal.ZERO) < 1){
            return BigDecimal.ONE;
        }
        return discountAmount;
    }

    @Override
    public CouponEnum getCoupon() {
        return CouponEnum.MJ;
    }
}
